//
//  AXFQuestionController.m
//  BeeQuick
//
//  Created by 王誉升 on 2016/11/24.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "AXFQuestionController.h"
#import "AXFQuestionModel.h"
#import "AXFQuestionCell.h"

static NSString *questionCell = @"questionCell";
@interface AXFQuestionController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,weak) UITableView *questionTV;

@end

@implementation AXFQuestionController
{
    NSArray <AXFQuestionModel *> *_questionList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)setupUI
{
    self.navigationItem.title = @"常见问题";
    
    UITableView *questionTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    
    [self.view addSubview:questionTableView];
    
    questionTableView.delegate = self;
    
    questionTableView.dataSource = self;
    
    [questionTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:questionCell];
    
    _questionTV = questionTableView;
    
    [self loadData];
    
    [_questionTV registerClass:[AXFQuestionCell class] forCellReuseIdentifier:questionCell];
    
    questionTableView.rowHeight = 65;

    //自定义导航条返回按钮
    UIBarButtonItem *leftBarB = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self action:@selector(clickToQuestion:)];
    
    self.navigationItem.leftBarButtonItem = leftBarB;
}

- (void)clickToQuestion:(UIBarButtonItem *)batBtn
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _questionList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AXFQuestionCell *cell = [tableView dequeueReusableCellWithIdentifier:questionCell forIndexPath:indexPath];
    
    cell.model = _questionList[indexPath.row];
    
    return cell;
}

- (void)loadData
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"QATalking.plist" withExtension:nil];
    
    NSArray *array = [NSArray arrayWithContentsOfURL:url];
    
    NSMutableArray *arrayM = [NSMutableArray array];
    
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        AXFQuestionModel *model = [AXFQuestionModel textWithDict:obj];
        
        [arrayM addObject:model];
        
    }];
    
    _questionList = arrayM.copy;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
